package com.tanhua.server.controller;

import com.tanhua.server.service.IMService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
@Slf4j
public class IMController {

    @Autowired
    private IMService imService;


    /**
     * 根据环信的ID号获取用户的信息
     * @param huanxinId
     * @return
     */
    @GetMapping("/user")
    public ResponseEntity getHuanxinUserInfo(Long huanxinId){
        log.info("==========IMController获取用户的信息========>");
        return imService.getHuanxinUserInfo(huanxinId);
    }


    /**
     *接口名称：联系人添加
     *接口路径：POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity addContact(@RequestBody Map<String,Object> paramMap){
        Integer friendId = (Integer) paramMap.get("userId");
        return imService.addContact(friendId);
    }


    /**
     *接口名称：联系人列表
     *接口路径：GET/messages/contacts
     *
     */
    @GetMapping("/contacts")
    public ResponseEntity queryContractList(@RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "10") Integer pagesize,String keyword){
        return imService.queryContractList(page,pagesize,keyword);
    }

    @GetMapping("/likes")
    public ResponseEntity<Object> getLikes(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.getLikes(page,pagesize);
    }

    @GetMapping("/comments")
    public ResponseEntity<Object> getComments(@RequestParam(defaultValue = "1") Integer page,
                                              @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.getComments(page,pagesize);
    }

    @GetMapping("/loves")
    public ResponseEntity<Object> getLoves(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.getLoves(page,pagesize);
    }

}
